package com.wzcl.app.controller;

import com.wzcl.app.model.common.RVO;
import com.wzcl.app.model.dto.CatalogReportDto;
import com.wzcl.app.model.dto.EssayCourseCatalogDto;
import com.wzcl.app.service.EssayCourseCatalogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * @author beingven
 * @Description 作文课章节管理
 * @createTime 2020年12月20日 14:24:00
 */
@RestController
@RequestMapping("/catalog")
@Api(value = "作文课章节管理controller", tags = {"作文课章节管理接口"})
public class EssayCourseCatalogController {
    @Resource
    private EssayCourseCatalogService essayCourseCatalogService;

    @ApiOperation("新增作文课章节")
    @PostMapping("/add")
    public RVO createCatalog(@RequestBody @Valid EssayCourseCatalogDto courseCatalogDto) throws InterruptedException {
        essayCourseCatalogService.createCatalog(courseCatalogDto);
        return RVO.success("数据保存成功");
    }

    @ApiOperation("删除作文课章节")
    @DeleteMapping("/delete/{id}")
    public RVO deleteCatalog(@PathVariable Integer id){
        essayCourseCatalogService.deleteCatalog(id);
        return RVO.success();
    }

    @ApiOperation("根据作文课id查询所有章节")
    @GetMapping("/retrieveAll/{courseId}")
    public RVO retrieveAll(@PathVariable Integer courseId){
        return RVO.success(essayCourseCatalogService.retrieveAll(courseId));
    }

    @ApiModelProperty("生成章节星星")
    @GetMapping("/generate/star/{catalogId}")
    public RVO getCatalogStar(@PathVariable Integer catalogId){
        return essayCourseCatalogService.getCatalogStar(catalogId);
    }

    @ApiOperation("生成章节报告")
    @GetMapping("/generate/report/{catalogId}")
    public RVO generateCatalogReport(@PathVariable Integer catalogId){
        return RVO.success(essayCourseCatalogService.generateCatalogReport(catalogId));
    }

    @ApiOperation("查询当前章节下的所有错题解析")
    @GetMapping("/retrieve/analysis/{catalogId}")
    public RVO retrieveAnalysisByCatalogId(@PathVariable Integer catalogId){
        return RVO.success(essayCourseCatalogService.retrieveAnalysisByCatalogId(catalogId));
    }
}